package com.hs.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.entity.MyConsult;
import com.hs.mapper.MyConsultMapper;
import com.hs.service.MyConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyConsultServiceImpl implements MyConsultService {
    @Autowired
    private MyConsultMapper myConsultMapper;
    @Override
    public int addMyConsult(MyConsult myConsult) {
        return myConsultMapper.addMyConsult(myConsult);
    }

    @Override
    public int deleteMyConsult(int id) {
        return myConsultMapper.deleteMyConsult(id);
    }

    @Override
    public int updateMyConsult(MyConsult myConsult) {
        return myConsultMapper.updateMyConsult(myConsult);
    }

    @Override
    public MyConsult getMyConsultById(int id) {
        return myConsultMapper.getMyConsultById(id);
    }

    @Override
    public PageInfo<MyConsult> getMyConsultByPage(MyConsult myConsult, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MyConsult> list = myConsultMapper.getMyConsultByPage(myConsult);
        PageInfo<MyConsult> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<MyConsult> getMyConsultByUserId(Integer userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<MyConsult> myConsultByUserId = myConsultMapper.getMyConsultByUserId(userId);
        PageInfo<MyConsult> pageInfo = new PageInfo<>(myConsultByUserId);
        return pageInfo;
    }
//已完成未完成
    @Override
    public List<MyConsult> getFinishedConsults(Integer userId) {
        return myConsultMapper.getMyConsultByIdAndStatus(userId,"已完成");
    }

    @Override
    public List<MyConsult> getUnfinishedConsults(Integer userId) {
        return myConsultMapper.getMyConsultByIdAndStatus(userId,"未完成");
    }

    @Override
    public boolean updateConsultStatus(Integer consultId) {
        // 根据ID查询咨询记录
        MyConsult consult = myConsultMapper.getMyConsultById(consultId);
        if (consult == null) {
            return false;
        }

        // 更新状态为"已完成"
        consult.setStatus("已完成");
        int rows = myConsultMapper.updateMyConsult(consult);
        return rows > 0;
    }

    @Override
    public int updateMyConsultByIds(Integer consultantId) {
        return myConsultMapper.updateMyConsultById(consultantId);
    }


}
